<?php

use app\components\BaseGridView;
use app\models\Activity;
use app\models\ActivityApply;
use yii\helpers\Html;
use yii\helpers\Url;

?>

<?= \admin\widgets\AdminTabs::widget([
    'items' => [
        Activity::CID_JOB => '实习',
        Activity::CID_PRACTICE => '兼职',
    ],
    'id' => 'cid',
]); ?>

<?= \admin\widgets\AdminTabs::widget([
    'items' => \app\models\Activity::$statusLabels,
    'id' => 'status',
]); ?>

<?php $status = Yii::$app->request->get('status'); if(!$status || $status != Activity::STATUS_DELETE): ?>
    <div class="row box" id="toolbar">
        <div class="col-md-9 col-sm-8 col-xs-7">
            <button href="<?= Url::to(['delete']); ?>" class="btn danger batch-delete">批量删除</button>
        </div>
    </div>
<?php endif; ?>

<?= BaseGridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        //['class' => 'yii\grid\SerialColumn'],
        ['class' => 'yii\grid\CheckboxColumn'],
        'id',
        ['attribute' => 'uid', 'value' => function (Activity $model) {
            return $model->user->uname;
        }],
        ['attribute' => 'title', 'contentOptions' => ['class' => 'text-left'], 'headerOptions' => ['class' => 'text-left']],
        ['label' => '时间', 'visible' => FALSE, 'value' => function ($model) {
            return date('Y-m-d', $model->start_time) . '~' . date('Y-m-d', $model->start_time);
        }],
        'company',
        'apply_number',
        ['attribute' => 'status', 'format' => 'raw', 'value' => function (Activity $model) {
            return $model->_statusLabel();
        }],
        ['attribute' => 'is_new', 'format' => 'raw', 'value' => function (Activity $model) {
            return $model->getIsNewLabel(Url::to(['set-new', 'id' => $model->id]));
        }],
        ['attribute' => 'is_hot', 'format' => 'raw', 'value' => function (Activity $model) {
            return $model->getIsHotLabel(Url::to(['set-hot', 'id' => $model->id]));
        }],
        'ctime:datetime',
        [
            'class' => 'app\components\BaseActionColumn',
            'template' => '{view} {apply-list} {delete} {undo}',
            'viewOptions' => ['title' => '查看', 'class1' => ''],
            'headerOptions' => ['width' => '15%'],
            'buttons' => [
                'apply-list' => function ($url, Activity $model, $key) {
                    return Html::a('查看报名', $url, ['class' => 'btn view']);
                },
                'undo' => function ($url, Activity $model, $key) {
                    if (!$model->getIsDelete()) {
                        return '';
                    }
                    return Html::a('<span class="fa fa-undo"></span>', $url, [
                        'class' => 'get',
                        'data-toggle' => 'tooltip',
                        'title' => '恢复'
                    ]);
                }
            ],
            'visibleButtons' => [
                'apply' => function (Activity $model, $key, $index) {
                    return !$model->getIsVerify();
                },
                'delete' => function (Activity $model, $key, $index) {
                    return !$model->getIsDelete();
                },
            ]
        ],
    ],
]); ?>
